<script setup>
import { ref } from 'vue'

const pwdInfo = ref({
    old_pwd: '',
    new_pwd: '',
    re_pwd: ''
})

const rules = {
    old_Pwd: [
        { required: true, message: '请输入信息', trigger: 'blur' },
        {
            pattern: /^\S{5,16}$/,
            message: '密码必须是5-16位的非空字符串',
            trigger: 'blur'
        }
    ],
    new_Pwd: [
        { required: true, message: '请输入信息', trigger: 'blur' },
        {
            pattern: /^\S{5,16}$/,
            message: '密码必须是5-16位的非空字符串',
            trigger: 'blur'
        }
    ],
    re_Pwd: [
        { required: true, message: '请输入信息', trigger: 'blur' },
        {
            pattern: /^\S{5,16}$/,
            message: '密码必须是5-16位的非空字符串',
            trigger: 'blur'
        }
    ]
}

//修改密码
import { userPwdUpdateService } from '@/api/user.js'
import { ElMessage } from 'element-plus'
const updatePwdInfo = async () => {
    console.log(pwdInfo.value);
    let result = await userPwdUpdateService(pwdInfo.value)
    ElMessage.success(result.message ? result.message : '修改成功')
}
</script>
<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>修改密码</span>
            </div>
        </template>
        <el-row>
            <el-col :span="12">
                <el-form :model="pwdInfo" :rules="rules" label-width="100px" size="large">
                    <el-form-item label="原密码" prop="old_pwd">
                        <el-input v-model="pwdInfo.old_pwd" show-password></el-input>
                    </el-form-item>
                    <el-form-item label="新密码" prop="new_pwd">
                        <el-input v-model="pwdInfo.new_pwd" show-password></el-input>
                    </el-form-item>
                    <el-form-item label="再次确认" prop="re_pwd">
                        <el-input v-model="pwdInfo.re_pwd" show-password></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="updatePwdInfo">提交修改</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </el-card>
</template>